package com.china08.yxyapi.api.manage.stu.mystudy.mistakes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.mistakes.StuMistakesQues;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.mistakes.StuMistakesQuesRepository;

/**
 * 错题本--学生端--修改是否重点题
 * 
 * @author LiuWeidong
 *
 */

@CrossOrigin
@RestController
public class YxyMistakesQuesCrtConditionController extends YxyApiBaseController {

    @Autowired
    private StuMistakesQuesRepository stuMistakesQuesRepository;

    @RequestMapping(value = "/api_yw/manage/stu/mystudy/mistake/condition/crt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel, RespModel respModel) {
        String studentId = reqModel.studentId;
        String quesId = reqModel.quesId;
        StuMistakesQues stuMistakesQues = stuMistakesQuesRepository.findByQuesIdAndStudentId(quesId, studentId);

        // 如果错题为非重点题改为重点题
        if (stuMistakesQues.getFocus() == 0) {
            stuMistakesQues.setFocus(1);
        }
        // 如果错题为重点题改为非重点题
        else {
            stuMistakesQues.setFocus(0);
        }
        stuMistakesQuesRepository.save(stuMistakesQues);
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiPageReqModel {

        // 试题ID
        public String quesId;
        // 学生ID
        public String studentId;

    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {

    }

}
